﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TaggerApp.ORD;
using TaggerApp.MSTagRefService;
using TaggerApp.Authentication;

namespace TaggerApp.Pages.AddUsers
{
    public partial class Default : System.Web.UI.Page
    {
        public string appName;
        protected void Page_Load(object sender, EventArgs e)
        {
            User myUser = (User)Session["user"];
            if (myUser == null)
            {
                Response.Redirect("~/Pages/Login");
            }
            if (!myUser.Role.Equals("Admin"))
            {
                Response.Redirect("~/Pages/Unauthorized/Unauthorized.aspx");
            }
            Global title = new Global();
            title.GetTitleFromDB();
            Page.Title = "Authorize a user - " + title.appName;

        }
        protected void Go_Click(object sender, EventArgs e)
        {
            using (mstaggerEntities context = new mstaggerEntities())
            {
                string role = context.getRole(txtEmail.Text).FirstOrDefault();
                if(role == null)
                context.insertAdministrator(txtEmail.Text);
            }
        }
    }
}